<?php
/**
 *教师修改、删除、增加
 */
include "../util/DBUtil.php";
include "../util/PromptAction.php";

$flag = $_GET['flag'];//判断是否是修改还是删除
$id = $_GET['id'];

$db = new DBUtil();
if ($flag==1){//删除
    $sql = "delete from tb_teacher where id= ? ";
    $params = array($id);
    $statue = $db->delete($sql,$params);
    showStatue($statue);
    echo "<script>window.open('teacher.php','info')</script>";
    return;
}elseif ($flag==0){//执行修改查询
    $sql = "select * from tb_teacher where id=? ";
    $params = array($id);
    $teacher_result = $db->query($sql,$params)[0];//教师结果
    $sql = "select * from tb_grade";
    $grade_result = $db->query($sql);//所有班级结果集
}
?>

<form action="../action/teacher_formOK.php" method="post">
    <input type="hidden" value="<?php echo $teacher_result['id']?>" name="id">
    <table>
        <tr>
            <td>编号：</td><td><input type="text" name="teacher_no" value="<?php echo $teacher_result['teacher_no']?>" maxlength="6" minlength="6"></td>
        </tr>
        <tr>
            <td>姓名：</td><td><input type="text" name="name" value="<?php echo $teacher_result['name']?>"></td>
        </tr>
        <tr>
            <td>密码：</td><td><input type="text" name="pwd" value="<?php echo $teacher_result['password']?>" maxlength="4" minlength="4"></td>
        </tr>
        <tr>
            <td>所管班级：</td><td>
                <select name="grade_id" id="">
                    <?php
                    foreach ($grade_result as $item){
                        ?>
                        <option value="<?php echo $item['id']?>" <?php echo $item['id']==$teacher_result['grade_id']? 'selected':'' ?> ><?php echo $item['grade']?></option>
                        <?php
                    }
                    ?>
                </select>
            </td>
        </tr>
    </table>
    <button type="submit">确定</button>
</form>
